package Server;


import Server.dao.SaleDao;
import Server.entity.Sale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Component
@Lazy(false)
public class ScheduledBoot {
    @Autowired
    private SaleDao saleDao;
    @Scheduled(cron = "0/1 * * * * ?")
    public void logTime(){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        Date currentTime = new Date();
        List<Sale> stages = saleDao.findByEndTimeLessThanAndStatusNot(formatter.format(currentTime),Sale.Status.NO);
        for(Sale stage:stages){
            stage.setStatus(Sale.Status.NO);
            saleDao.save(stage);
        }
    }
}
